package com.gxc.service;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.async.DeferredResult;

/**
 * 定时异步任务.
 *
 * @author 宫新程
 * @since 2018/12/18 2:21 PM
 */
@Service
public class PushService {

  private DeferredResult<String> deferredResult;

  public DeferredResult<String> getAsyncUpdate() {
    deferredResult = new DeferredResult<>();
    return deferredResult;
  }

  /** 定时任务：每5秒执行. */
  @Scheduled(fixedDelay = 5000)
  public void refresh() {
    if (deferredResult != null) {
      deferredResult.setResult(new Long(System.currentTimeMillis()).toString());
    }
  }
}
